package com.neo.rabbitmq.six;

import com.neo.rabbitmq.utils.RabbitMqUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName: EmitLogDirect
 * @Title: rabbitmq-demo
 * @Package: com.neo.rabbitmq.six
 * @Description:
 * @Author: Kisen
 * @Date: 2021/9/14 21:56
 */
public class EmitLogDirect {

    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtil.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String message = sc.next();
            String routingKey = "error"; // info, warning, error
            channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes("UTF-8"));
            System.out.println("生产者发出消息：" + message);
        }
    }
}
